package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.net.userService
import com.polaris.live.resp.back_resp.DiamondResp
import com.polaris.live.resp.base.ListResp
import com.polaris.live.widget.refresh.OnListListener

/**
 * DiamondViewModel
 *
 * @author Created by 半仙 on 2023/10/26/026 15:51
 */
class GameBeansViewModel : BaseViewModel(), OnListListener {

    val diamondLiveData = MutableLiveData<ResultState<ListResp<DiamondResp>>>()
    val pageSize = 20  // 每页记录数
    var userCoinDetailSourceType: Int? = null

    fun coinDiamond(
        pageNumber: Int,
        pageSize: Int = this.pageSize,
        userCoinDetailSourceType: Int? = this.userCoinDetailSourceType,
    ) {
        request(
            { userService.coinDetail(pageNumber, pageSize, userCoinDetailSourceType) },
            diamondLiveData
        )
    }

    override fun onRefresh() {
        coinDiamond(pageNumber = 0)
    }

    override fun onLoadMore(pageIndex: Int) {
        coinDiamond(pageNumber = pageIndex)
    }

}